#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QToolBar>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    QMenuBar* menuBar = this->menuBar();
    this->setMenuBar(menuBar);

    QMenu* menu1 = new QMenu("菜单1");
    QMenu* menu2 = new QMenu("菜单2");

    QAction* act1 = new QAction("打开");
    QAction* act2 = new QAction("保存");
    QAction* act3 = new QAction("关闭");

    QIcon icon(":/pic.jpg");
    act1->setIcon(icon);

    menuBar->addMenu(menu1);
    menuBar->addMenu(menu2);

    menu1->addAction(act1);
    menu1->addAction(act2);
    menu1->addAction(act3);
    //创建工具栏
    QToolBar* toolBar = new QToolBar();
    this->addToolBar(Qt::LeftToolBarArea,toolBar);
    toolBar->setAllowedAreas(Qt::LeftToolBarArea | Qt::RightToolBarArea);
    toolBar->setFloatable(false);

    toolBar->setMovable(false);
    toolBar->addAction(act1);
    toolBar->addAction(act2);
    toolBar->addAction(act3);

    connect(act3,&QAction::triggered,this,&MainWindow::close);

}

MainWindow::~MainWindow()
{
    delete ui;
}

